import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class Task implements Delayed {
    //任务执行的时间
    private long executeTime;
    private String name;

    public Task(long delaySecond, String name) {
        this.executeTime = System.currentTimeMillis()+1000* delaySecond;
        this.name = name;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        long diff = this.executeTime-System.currentTimeMillis();
        return unit.convert(diff,TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        Task other = (Task) o;
        return Long.compare(this.executeTime,other.executeTime);
    }
    public String getName(){
        return name;
    }
}
